<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			body { margin: 0; }
		</style>
		<script src="../utils/setTitle.js"></script>
	</head>
	<body>
		<script type="importmap">
			{
				"imports": {
					"three": "https://unpkg.com/three/build/three.module.js"
				}
			}
		</script>
		<script type="module">
			import * as THREE from 'three';
			import { BVHLoader } from 'https://unpkg.com/three/examples/jsm/loaders/BVHLoader';

			const scene = new THREE.Scene();
			const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
			const geometry = new THREE.BoxGeometry( 1, 1, 1 );
			const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
			
			const loader = new BVHLoader();
			let mixer 
			loader.load( './pirouette.bvh', function ( result ) {

				const skeletonHelper = new THREE.SkeletonHelper( result.skeleton.bones[ 0 ] );

				scene.add( result.skeleton.bones[ 0 ] );
				scene.add( skeletonHelper );
				mixer = new THREE.AnimationMixer( result.skeleton.bones[ 0 ] );
				mixer.clipAction( result.clip ).play();
			} );
			camera.position.z = 550;
			camera.position.y = 2;
			const renderer = new THREE.WebGLRenderer();
			renderer.setSize( window.innerWidth, window.innerHeight );
			document.body.appendChild( renderer.domElement );
			const clock = new THREE.Clock();

			function animate() {
				requestAnimationFrame( animate );
				const delta = clock.getDelta();
				if ( mixer ) mixer.update( delta );
				renderer.setSize( window.innerWidth, window.innerHeight );
				renderer.render( scene, camera );
			}
			animate();
		</script>
	</body>
</html>